Option Strict Off
Option Explicit On
Friend Class Form1
	Inherits System.Windows.Forms.Form
	
    Private Declare Function ECF_AbrePortaSerial Lib "CONVECF.DLL" () As Integer
    Private Declare Function ECF_FechaPortaSerial Lib "CONVECF.DLL" () As Integer
	
	Private Sub Cmd01_AbrePorta_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd01_AbrePorta.Click
		Dim retorno As Object

        retorno = ECF_AbrePortaSerial

        MsgBox(" 'Abre Porta' " & vbCrLf & "Status: " & retorno, MsgBoxStyle.Information)
    End Sub

    Private Sub Cmd02_FechaPorta_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd02_FechaPorta.Click
        Dim retorno As Object

        retorno = ECF_FechaPortaSerial

        MsgBox(" 'Fecha Porta' " & vbCrLf & "Status: " & retorno, MsgBoxStyle.Information)
    End Sub

    Private Sub Cmd03_ProgramarTaxas_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd03_ProgramarTaxas.Click
        ''''''Modulo 22 - Programar Aliquotas''''''''''

        ProgramarAliquotasTributarias()
    End Sub

    Private Sub Cmd04_MeioPagamento_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd04_MeioPagamento.Click
        ''''''Modulo 23 - Programar Meios de Pagamentos''''''''''

        ProgramarMeiosPagamento()
    End Sub

    Private Sub Cmd05_Totalizador_NaoFiscal_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd05_Totalizador_NaoFiscal.Click
        ''''''Modulo 24 - Programar Totalizadores Não-Fiscais''''''''''

        ProgramarTotalizadoresNaoFiscais()
    End Sub

    Private Sub Cmd06_ProgramarRelatorio_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd06_ProgramarRelatorio.Click
        ''''''Modulo 21 - Programar Relatório''''''''''

        ProgramarLegendaRelatorio()
    End Sub



    Private Sub Cmd07_CupomFiscal_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd07_CupomFiscal.Click
        ''''''Modulo 1 - Cupom Fiscal''''''''''
        CupomFiscal()
    End Sub



    Private Sub Cmd08_CancelarCupom_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd08_CancelarCupom.Click
        ''''''Modulo 17 - Cancelar Cupom''''''''''
        CancelarCupom()
    End Sub


    Private Sub Cmd09_Vinculado_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd09_Vinculado.Click
        ''''''Modulo 19 - Cupom Vinculado''''''''''
        CupomVinculado()
    End Sub

    Private Sub Cmd10_ReimpressaoVinculado_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd10_ReimpressaoVinculado.Click
        ''''''Modulo 19 - Cupom Vinculado''''''''''
        ReimpressaoVinculado()
    End Sub

    Private Sub Cmd11_Estorno_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd11_Estorno.Click
        ''''''Modulo 19 - Cupom Vinculado''''''''''
        EstornoVinculado()
    End Sub

    Private Sub Cmd12_Comprovante_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd12_Comprovante.Click
        ''''''Modulo 20 - Cupom Não Fiscal''''''''''
        CupomNaoFiscal()
    End Sub

    Private Sub Cmd13_SaidaDeCaixa_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd13_SaidaDeCaixa.Click
        ''''''Modulo 20 - Cupom Não Fiscal''''''''''
        CupomNaoFiscalSaidaDeCaixa()
    End Sub

    Private Sub Cmd14_Sangria_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd14_Sangria.Click
        ''''''Modulo 20 - Cupom Não Fiscal''''''''''
        SaidaDeCaixa_Sangria()
    End Sub

    Private Sub Cmd15_Suprimento_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd15_Suprimento.Click
        ''''''Modulo 20 - Cupom Não Fiscal''''''''''
        EntradaSuprimentos()
    End Sub

    Private Sub Cmd16_Recebimento_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd16_Recebimento.Click
        ''''''Modulo 20 - Cupom Não Fiscal''''''''''
        RecebimentosNaoFiscais()
    End Sub

    Private Sub Cmd17_Z_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd17_Z.Click
        ''''''Modulo 3 - Redução Z''''''''''
        ReducaoZ()
    End Sub

    Private Sub Cmd18_X_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd18_X.Click
        ''''''Modulo 2 - Leitura X''''''''''
        LeituraX()
    End Sub

    Private Sub Cmd19_Parametros_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd19_Parametros.Click
        ''''''Modulo 25 - Leitura de Parametros'''''''''
        LeituraDeParametros()
    End Sub

    Private Sub Cmd20_MFD_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd20_MFD.Click
        ''''''Modulo 5 - Download MFD''''''''''
        DownloadMFD()
    End Sub

    Private Sub Cmd21_LMFData_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd21_LMFData.Click
        ''''''Modulo 4 - L.M. Fiscal''''''''''
        LMFData()
    End Sub

    Private Sub Cmd22_LMFDataSerial_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd22_LMFDataSerial.Click
        ''''''Modulo 4 - L.M. Fiscal''''''''''
        LMFDataSerial()
    End Sub

    Private Sub Cmd23_LMFreducoes_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd23_LMFreducoes.Click
        ''''''Modulo 4 - L.M. Fiscal''''''''''
        LMFReducao()
    End Sub

    Private Sub Cmd24_LMFreducoesSerial_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd24_LMFreducoesSerial.Click
        ''''''Modulo 4 - L.M. Fiscal''''''''''
        LMFReducaoSerial()
    End Sub

    Private Sub Cmd25_RelatorioGerencial_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd25_RelatorioGerencial.Click
        ''''''Modulo 18 - Relatorio Gerencial''''''''''
        RelatorioGerencial()
    End Sub

    Private Sub Cmd26_Sintegra_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd26_Sintegra.Click
        ''''''Modulo 16 - Sintegra''''''''''

        'As funções do Sintegra gera o Arquivo Retorno.txt''''''
        'Com o Padrão Tipo60, ou 60Mestre, ou 60Analitico

        RegistrosTipo60()
        'RelatorioTipo60Mestre()
        'RelatorioTipo60AnaliticoMFD()

    End Sub

    Private Sub Cmd27_Status_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd27_Status.Click
        ''''''Modulo 13 - Status_ECF'''''''''
        List1.Items.Clear()
        ImpressoraLigada()
        FlagsFiscais()
        EstadoImpressora()
        RetornoImpressora()
        StatusEstendido()
    End Sub

    Private Sub Cmd28_UltimaTransacao_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd28_UltimaTransacao.Click
        ''''''Modulo 12 - Retorno Ultima Transacao'''''''''
        List1.Items.Clear()
        UltimoItemVendido()
        SubTotalCF()
        SubTotalCNF()
        ValorPagoUltimoCupom()
        NumeroCupom()
        VerificaFormasPagamento()
    End Sub

    Private Sub Cmd29_Diversos_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd29_Diversos.Click
        ''''''Modulo 14 - Retorno_Diversos'''''''''
        List1.Items.Clear()
        PercentualLivreMFD()
        TotalLivreMFD()
        ReducoesRestantes()
        TamanhoTotalMFD()
        DataMovimento()
    End Sub

    Private Sub Cmd30_DadosUsuario_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd30_DadosUsuario.Click
        ''''''Modulo 7 - Dados do Usuário'''''''''
        List1.Items.Clear()
        CNPJUsuario()
        IEUsuario()
        NumCaixa()
        SimboloMoeda()
        ClicheProprietario()
    End Sub

    Private Sub Cmd31_Aliquotas_Totalizadores_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd31_Aliquotas_Totalizadores.Click
        ''''''Modulo 8 - Aliq & Tolalizadores não Fiscais'''''''''
        List1.Items.Clear()
        Aliquotas()
        TotalizadoresNaoFiscais()
    End Sub

    Private Sub Cmd32_Contadores_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd32_Contadores.Click
        ''''''Modulo 11 - Contadores'''''''''
        List1.Items.Clear()
        NumIntervencoes()
        NumCupomFiscal()
        NumCuponsCancelados()
        OperacoesNaoFiscais()
        ContTotalizadoresNaoFiscais()
        RGerencial()
        NumComprovantesCredito()
        OperacoesNFCanceladas()
        ContadorMFD()
        ContadorRG()
        ContadorRZ()
    End Sub

    Private Sub Cmd33_TotalizadoresDiarios_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd33_TotalizadoresDiarios.Click
        ''''''Modulo 10 - Acumuladores Diários'''''''''
        List1.Items.Clear()
        Acrescimos()
        Descontos()
        ValorFormaPagamento()
        ValorTotalizadorNaoFiscal()
        VerificaRecebimentoNaoFiscal()
        Cancelamentos()
        GrandeTotal()
        VerificaTotalizadoresParciais()
    End Sub

    Private Sub Cmd34_ValoresReducao_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd34_ValoresReducao.Click
        ''''''Modulo 15 - Retorno_Após_Redução'''''''''
        List1.Items.Clear()
        DataHoraUltimoDocumento()
        DataHoraReducao()
        DataMovimentoUltimaReducao()
        COOInicialFinal()
        GTInicialFinal()
        GTUltimaReducao()
        DadosUltimaReducao()
        MapaResumo()
    End Sub

    Private Sub Cmd35_Versao_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd35_Versao.Click
        ''''''Modulo 6 - Série_Versão'''''''''
        List1.Items.Clear()
        VersaoDll()
        VersaoFirmwareMFD()
    End Sub


    Private Sub Cmd36_Serie_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd36_Serie.Click
        ''''''Modulo 6 - Série_Versão'''''''''
        List1.Items.Clear()
        NumSerieMFD()
        SerieMemoriaMFD()
    End Sub

    Private Sub Cmd37_DataModo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cmd37_DataModo.Click
        ''''''Modulo 9 - Modo & Data'''''''''
        List1.Items.Clear()
        DataHora()
        ModoOperacao()
    End Sub


    Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        Dim Msg As Object
        Dim retorno As Object

        retorno = ECF_AbrePortaSerial
        List1.Items.Clear()
        MsgBox(" 'ECF_AbrePortaSerial' " & vbCrLf & "Status: " & retorno, MsgBoxStyle.Information)

        Msg = MsgBox("A Parametrização do Ecf deve ser feita pelo Connect C, para que seja possível emitir todos os documentos." & vbCrLf & "Os seguintes parâmetros devem ser Programados:" & " Alíquotas, Meio de Pagamentos, Totalizadores Não-Fiscal, Legendas de Relatório Gerencial", MsgBoxStyle.Information, "CONNECT C")


    End Sub

    Private Sub Form1_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Dim retorno As Object

        retorno = ECF_FechaPortaSerial
        MsgBox(" 'ECF_FechaPortaSerial' " & vbCrLf & "Status: " & retorno, MsgBoxStyle.Information)
    End Sub
End Class